<script setup lang="ts" name="GoodsHot">
import { IResponse } from "@/types/data";
import { CategoryGoods } from "@/types/goods";
import request from "@/utils/request";
import GoodsItem from "@/views/category/components/goods-item.vue";
import { PropType, ref } from "vue";
import { useRoute } from "vue-router";

// #1
const props = defineProps({
  type: {
    type: Number as PropType<1 | 2 | 3>,
    default: 1,
  },
});
// #2
const titleObj = {
  1: "24小时热销榜",
  2: "周热销榜",
  3: "总热销榜",
};
const list = ref<CategoryGoods[]>([]);
const route = useRoute();
const goodsId = route.params.id as string;
const getList = async () => {
  const r = await request.get<IResponse<CategoryGoods[]>>("/goods/hot", {
    params: {
      id: goodsId,
      type: props.type,
    },
  });
  console.log(r.data.result);

  list.value = r.data.result;
};
getList();
</script>

<template>
  <div class="goods-hot">
    <h3>{{ titleObj[props.type] }}</h3>
    <div class="goods-list">
      <GoodsItem v-for="item in list" :goods="item" />
    </div>
  </div>
</template>

<style scoped lang="less">
.goods-hot {
  background-color: #fff;
  margin-bottom: 20px;
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }
  .goods-list {
    display: flex;
    flex-direction: column;
    align-items: center;
  }
}
</style>
